import request from '@/utils/request'
import type { Message, NewMessage } from '@/types/guestbook'

interface MessageResponse {
    list: Message[]
    total: number
    hasMore: boolean
}

interface ReplyParams {
    content: string
}

// 获取留言列表
export const getMessages = (params: {
    page: number
    pageSize: number
    keyword?: string
}) => {
    return request.get<MessageResponse>('/guestbook/list', params)
}

// 发表留言
export const createMessage = (data: NewMessage) => {
    return request.post<Message>('/guestbook/create', data)
}

// 回复留言
export const replyMessage = (data: {
    messageId: number
    nickname: string
    email?: string
    content: string
}) => {
    return request.post<Message>('/guestbook/reply', data)
}

// 点赞留言
export const likeMessage = (messageId: number) => {
    return request.post<{
        likes: number
        isLiked: boolean
    }>(`/guestbook/like/${messageId}`)
}

// 删除留言（管理员）
export const deleteMessage = (messageId: number) => {
    return request.delete(`/guestbook/delete/${messageId}`)
}

// 删除回复（管理员）
export const deleteReply = (messageId: number, replyId: number) => {
    return request.delete(`/guestbook/${messageId}/reply/${replyId}`)
}

// 添加回复
export function addReply(messageId: number, data: ReplyParams) {
    return request.post<Message>(
        `/guestbook/messages/${messageId}/replies`,
        data
    )
} 